//
//  SSOrderDetailMealCell.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/3/10.
//

import UIKit

class SSOrderDetailMealCell: UITableViewCell {
    @IBOutlet weak var indexLab: UILabel!
    
    @IBOutlet weak var nameLab: UILabel!
    @IBOutlet weak var priceLab: UILabel!
    override func awakeFromNib() {
        super.awakeFromNib()
        selectionStyle = .none
    }

    func setData(order:ListCombo, index:Int) {
        indexLab.text = "\(index + 1)"
        nameLab.text = order.name
        priceLab.text = "$\(order.totalFee)"
        
        if order.specs.count > 0 {
            var y:CGFloat = 0
            addSubview(bgView)
            if bgView.subviews.count>0{
                bgView.subviews.forEach({$0.removeFromSuperview()})
            }
            for spec in order.specs {
                let lab = UILabel()
                lab.text = spec.name
                lab.textColor = UIColor.init(hex: "#1A1A1A")?.withAlphaComponent(0.6)
//                lab.textColor = UIColor.red
                lab.font = UIFont.systemFont(ofSize: 14)
                bgView.addSubview(lab)
                lab.frame = CGRect(x: 0, y: y, width: 300, height: 19)
                y = lab.frame.maxY + 4
            }
            bgView.frame = CGRect(x: 50, y: 34, width: ScreenWidth - 50 - 16, height: y )
        }else{
            if bgView.subviews.count>0{
                bgView.subviews.forEach({$0.removeFromSuperview()})
            }
            bgView.removeFromSuperview()
        }
        
    }
    
    lazy var bgView:UIView = {
        let view = UIView()
        view.frame = CGRect(x: 50, y: 34, width: ScreenWidth - 50 - 16, height: 19)
//        view.backgroundColor = UIColor.blue
        return view
    }()
    
}
